﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TCEasyPrintRev.Models;

namespace TCEasyPrintRev.Controllers
{ 
    public class CetakController
    {
        private static string autoIncrement()
        {
            string akhir;
            int angka;
            try{
                
                using (var session = CRUD<Cetak>.load().OpenSession())
                {
                akhir = session.QueryOver<Cetak>().List().Last().ID;

        
                }

            

                
               string[] x = akhir.Split('C').ToArray(); angka = int.Parse(x[1]) + 1; }

                catch { angka = 1; }

            


            if (angka.ToString().Count() == 1)
                return "C0000" + angka;
            else if (angka.ToString().Count() == 2)
                return "C000" + angka;
            else if (angka.ToString().Count() == 3)
                return "C00" + angka;
            else if (angka.ToString().Count() == 4)
                return "C0" + angka;
            else
                return angka.ToString();
        }
        public  static string insert(WCF_File.CetakS file , string id ,string id2)
        {
            file.ID = autoIncrement();
            file.isDone = false;
            file.isvalid = false;
            

            Cetak x = new Cetak(file);
            x.paket = PaketController.getPaketByID(id);
            x.file = FileController.getFileByID(id2);

            CRUD<Cetak>.insert(x);

            return file.ID;
        }

      
    }
}